#!/usr/bin/python

DIM = 20

def robber_move(dr, c1, c2, c3):
	field = Field(DIM,DIM)

	field.set(Robber(dr[0],dr[1]))
	field.set(Cop(c1[0],c1[1]))
	field.set(Cop(c2[0],c2[1]))
	field.set(Cop(c3[0],c3[1]))

	field.diffuse()
	cell = field.move()
	print '{0:d} {0:d}'.format(cell.x, cell.y)

class Cell:
	def __init__(self, x, y):
		self.x    = x
		self.y    = y
		self.heat = 0.0

class Robber(Cell):
	pass

class Cop(Cell):
	pass

class Field:
	def __init__(self, size_x, size_y):
		self.size_x = size_x
		self.size_y = size_y
		self.robber = None
		self.cops   = []
		self.cells  = [[0 for x in xrange(self.size_x)] for x in xrange(self.size_y)]

		self.initialize()

	def initialize(self):
		for x in xrange(self.size_x):
			for y in xrange(self.size_y):
				self.set(Cell(x,y))

	def show(self):
		for x in xrange(self.size_x):
			for y in xrange(self.size_y):
				inst = self.get(x,y)
				if isinstance(inst, Robber):
					print 'R',
				elif isinstance(inst, Cop):
					print 'C',
				else:
					print ' ',

				if y == self.size_y - 1:
					print ''

	def get(self, x, y):
		if x < 0 or x >= self.size_x or y < 0 or y >= self.size_y:
			return None

		return self.cells[x][y]

	def set(self, cell):
		self.cells[cell.x][cell.y] = cell

		if isinstance(cell, Robber):
			self.robber = cell
		elif isinstance(cell, Cop):
			self.cops.append(cell)

	def merge_heat(self, other):
		for x in xrange(self.size_x):
			for y in xrange(self.size_y):
				self.get(x,y).heat += other.get(x,y).heat

	def diffuse(self):
		self.diffuse_cops()
		self.diffuse_walls()

	def diffuse_cops(self):
		for cop in self.cops:
			heat_field = Field(self.size_x, self.size_y)
			heat_field.diffuse_from(heat_field.get(cop.x,cop.y), 32.0)
			self.merge_heat(heat_field)

	def diffuse_walls(self):
		heat_field = Field(self.size_x, self.size_y)

		for x in xrange(self.size_x):
			heat_field.diffuse_from(heat_field.get(x,0), 8.0)
			heat_field.diffuse_from(heat_field.get(x,self.size_y - 1), 8.0)

		for y in xrange(self.size_y):
			heat_field.diffuse_from(heat_field.get(0,y), 8.0)
			heat_field.diffuse_from(heat_field.get(self.size_x - 1,y), 8.0)

		self.merge_heat(heat_field)

	def diffuse_from(self, cell, heat):
		cell.heat = heat
		new_heat = heat / 2.0

		for neighbor in self.neighbors(cell):
			if neighbor.heat < new_heat:
				self.diffuse_from(neighbor, new_heat)

	def neighbors(self, cell):
		n1 = self.get(cell.x - 1, cell.y)
		n2 = self.get(cell.x + 1, cell.y)
		n3 = self.get(cell.x, cell.y - 1)
		n4 = self.get(cell.x, cell.y + 1)

		neighbors = []
		if n1 != None:
			neighbors.append(n1)
		if n2 != None:
			neighbors.append(n2)
		if n3 != None:
			neighbors.append(n3)
		if n4 != None:
			neighbors.append(n4)

		return neighbors

	def movable_cells(self, cell):
		movable = []

		for x in xrange(-1,2):
			for y in xrange(-1,2):
				c = self.get(cell.x + x, cell.y + y)
				if c != None:
					movable.append(c)

		return movable

	def move(self):
		movable = self.movable_cells(self.robber)
		best = None
		for cell in movable:
			if best == None or cell.heat < best.heat:
				best = cell

		return best

robber_move([19,19], [0,0], [0,0], [0,0])